/**
 * PreviewImageItem.java Create on 2012-8-1     
 *      
 * Copyright (c) 2012-8-1 by yiming     
 *      
 * @author <a href="alenzhangym@hotmail.com">Yiming</a>     
 * @version 1.0 
 */

package com.yimi.service;

import android.os.Parcel;
import android.util.Log;

/**
 * TODO ��������
 * 
 * @author Yiming
 * @version 1.0
 */
public class PreviewImageItem extends BaseImageItem {
    private static String TAG = "PreviewImageItem";
    private byte[] preview;
    private int lenth;

    PreviewImageItem() {
        super();
    }
    public PreviewImageItem(Parcel in) {    
        this.readFromParcel(in);
    }
    
    public PreviewImageItem(BaseImageItem baseImageItem) {
        super(baseImageItem);
    }

    /**
     * @return the preview
     */
    public byte[] getPreview() {
        return preview;
    }

    public void writePacel(Parcel dest, int flags) {
        super.writePacel(dest, flags);
        Log.e(TAG, "super  write over");
        dest.writeInt(lenth);
        Log.e(TAG, "write lenth is " + lenth);
        dest.writeByteArray(preview);
        Log.e(TAG, "end  write");
    }

    public void readFromParcel(Parcel in) {
        Log.e(TAG, "Start to read");
        super.readFromParcel(in);
        this.lenth = in.readInt();
        Log.e(TAG, "length is " + lenth); 
        preview = new byte[lenth]; 
        in.readByteArray(preview);
        Log.e(TAG, "end to read");
    }
    
    public void readToParcel(Parcel in){
        super.readToParcel(in);
        this.lenth = in.readInt();
        Log.e(TAG, "length is " + lenth); 
        preview = new byte[lenth]; 
        in.readByteArray(preview);
        Log.e(TAG, "end to read");
    }
    
    /**
     * @param preview the preview to set
     */
    public void setPreview(byte[] srcPreview) {
        if (srcPreview != null) {
            preview = new byte[srcPreview.length];
            System.arraycopy(srcPreview, 0, preview, 0, srcPreview.length);
            lenth = srcPreview.length;
        }
    }
    
   public String toString(){
       String s = super.toString();
       s+=" lenth=";
       s+=lenth;
       return s;
   }
}
